package cn.le.beans.dto;

import cn.hutool.core.date.DateUtil;
import cn.le.utils.SqlUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @Description
 * @Author le
 * @Date 2020/2/16 18:04
 * @Version 0.1
 **/
@ApiModel(value = "房源Excel检索")
@Data
public class ExcelHomeSearchDto extends BasePage{

    @ApiModelProperty(value = "小区")
    private String name;

    public String getName(){
        return SqlUtils.like("name",name);
    }

    @ApiModelProperty(value = "地区")
    private String region;

    public String getRegion(){
        return SqlUtils.like("region",region);
    }

    @ApiModelProperty(value = "年代")
    private String years;

    public String getYears(){
        return SqlUtils.equivalent("years",years);
    }

    @ApiModelProperty(value = "楼层")
    private String floor;

    public String getFloor(){
        return SqlUtils.equivalent("floor",floor);
    }

    @ApiModelProperty(value = "装修")
    private String renovation;

    public String getRenovation(){
        return SqlUtils.like("renovation",renovation);
    }

    @ApiModelProperty(value = "户型")
    private String houseType;

    public String getHouseType(){
        return SqlUtils.like("house_type",houseType);
    }

    @ApiModelProperty(value = "面积")
    private String area;

    public String getArea(){
        return SqlUtils.equivalent("area",area);
    }


    @ApiModelProperty(value = "起拍价")
    private String startingPrice;

    @ApiModelProperty(value = "折扣")
    private String  discount;

    private String getDiscount(){
        return SqlUtils.equivalent("discount",discount);
    }

    public String getStartingPrice(){
        return SqlUtils.equivalent("starting_price",startingPrice);
    }


    @ApiModelProperty(value = "拍卖时间")
    private Date startDate;
    @ApiModelProperty(value = "地铁")
    private String metro;
    @ApiModelProperty(value = "新增日期")
    private Date createDate;

    public String getCreateDate(){
        if (createDate == null){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" and create_date >= '").append(DateUtil.format(createDate, "yyyy-MM-dd")).append("'");
        return sb.toString();
    }

    public String getMetro(){
        if (StringUtils.isEmpty(metro)){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" and metro is not null ");
        return sb.toString();
    }

    public String getStartDate(){
        if (startDate == null){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(" and auction_time > '").append(DateUtil.format(startDate, "yyyy-MM-dd")).append("'");
        return sb.toString();
    }
}
